package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicUserExperience;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicUserExperienceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户经历Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/basic/experience")
public class BasicUserExperienceController extends BaseController {

    @Resource
    private IBasicUserExperienceService basicUserExperienceService;

    /**
     * 查询用户经历列表
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicUserExperience basicUserExperience) {
        startPage();
        List<BasicUserExperience> list = basicUserExperienceService.selectBasicUserExperienceList(basicUserExperience);
        return getDataTable(list);
    }

    /**
     * 导出用户经历列表
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:export')")
    @Log(title = "用户经历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicUserExperience basicUserExperience) {
        List<BasicUserExperience> list = basicUserExperienceService.selectBasicUserExperienceList(basicUserExperience);
        ExcelUtil<BasicUserExperience> util = new ExcelUtil<BasicUserExperience>(BasicUserExperience.class);
        util.exportExcel(response, list, "用户经历数据");
    }

    /**
     * 获取用户经历详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicUserExperienceService.selectBasicUserExperienceById(id));
    }

    /**
     * 新增用户经历
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:add')")
    @Log(title = "用户经历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicUserExperience basicUserExperience) {
        return toAjax(basicUserExperienceService.insertBasicUserExperience(basicUserExperience));
    }

    /**
     * 修改用户经历
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:edit')")
    @Log(title = "用户经历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicUserExperience basicUserExperience) {
        return toAjax(basicUserExperienceService.updateBasicUserExperience(basicUserExperience));
    }

    /**
     * 删除用户经历
     */
    @PreAuthorize("@ss.hasPermi('basic:experience:remove')")
    @Log(title = "用户经历", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicUserExperienceService.deleteBasicUserExperienceByIds(ids));
    }
}
